﻿namespace HRM.CORE
{
    using APP.HELPER.Data.Helper;
    using APP.HELPER.Utils.CustomizeToolbox;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Repository;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms; using Common;

    public class HRM_TIMEKEEPER_TABLELIST
    {
        private bool m_IsFinish;
        private bool m_IsLock;
        private int m_Month;
        private Guid m_TimeKeeperTableListID;
        private string m_TimeKeeperTableListName;
        private int m_Year;

        public HRM_TIMEKEEPER_TABLELIST()
        {
            this.m_TimeKeeperTableListID = Guid.NewGuid();
            this.m_TimeKeeperTableListName = "";
            this.m_Month = 0;
            this.m_Year = 0;
            this.m_IsLock = true;
            this.m_IsFinish = true;
        }

        public HRM_TIMEKEEPER_TABLELIST(Guid TimeKeeperTableListID, string TimeKeeperTableListName, int Month, int Year, bool IsLock, bool IsFinish)
        {
            this.m_TimeKeeperTableListID = TimeKeeperTableListID;
            this.m_TimeKeeperTableListName = TimeKeeperTableListName;
            this.m_Month = Month;
            this.m_Year = Year;
            this.m_IsLock = IsLock;
            this.m_IsFinish = IsFinish;
        }

        public void AddCombo(System.Windows.Forms.ComboBox combo)
        {
            GridCalendarControlLib.TableToComboBox(combo, this.GetList(), "TimeKeeperTableListName", "TimeKeeperTableListID");
        }

        public void AddComboAll(System.Windows.Forms.ComboBox combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["TimeKeeperTableListID"] = "All";
            row["TimeKeeperTableListName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            GridCalendarControlLib.TableToComboBox(combo, list, "TimeKeeperTableListName", "TimeKeeperTableListID");
        }

        public void AddComboEdit(ComboBoxEdit combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            foreach (DataRow row in list.Rows)
            {
                combo.Properties.Items.Add(row["TimeKeeperTableListName"]);
            }
        }

        public void AddGridLookupEdit(GridLookUpEdit gridlookup)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            gridlookup.Properties.DataSource = list;
            gridlookup.Properties.DisplayMember = "TimeKeeperTableListName";
            gridlookup.Properties.ValueMember = "TimeKeeperTableListID";
        }

        public void AddRepositoryGridLookupEdit(RepositoryItemGridLookUpEdit gridlookup)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            gridlookup.DataSource = list;
            gridlookup.DisplayMember = "TimeKeeperTableListName";
            gridlookup.ValueMember = "TimeKeeperTableListID";
        }

        public void AddRepositoryGridLookupEditByYear(RepositoryItemGridLookUpEdit gridlookup, int Year)
        {
            DataTable listByYear = new DataTable();
            listByYear = this.GetListByYear(Year);
            if (listByYear.Rows.Count >= 0)
            {
                gridlookup.DataSource = listByYear;
                gridlookup.DisplayMember = "TimeKeeperTableListName";
                gridlookup.ValueMember = "TimeKeeperTableListID";
            }
            else
            {
                gridlookup.DataSource = null;
                gridlookup.NullText = "[Chọn bảng chấm c\x00f4ng]";
            }
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID" };
            object[] myValues = new object[] { this.m_TimeKeeperTableListID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_TABLELIST_Delete", myParams, myValues);
        }

        public string Delete(string TimeKeeperTableListID)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID" };
            object[] myValues = new object[] { TimeKeeperTableListID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_TABLELIST_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string TimeKeeperTableListID)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID" };
            object[] myValues = new object[] { TimeKeeperTableListID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_TIMEKEEPER_TABLELIST_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string TimeKeeperTableListID)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID" };
            object[] myValues = new object[] { TimeKeeperTableListID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_TIMEKEEPER_TABLELIST_Delete", myParams, myValues);
        }

        public string Delete(int Month, int Year)
        {
            string[] myParams = new string[] { "@Month", "@Year" };
            object[] myValues = new object[] { Month, Year };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_TABLELIST_DeleteBy", myParams, myValues);
        }

        public bool Exist(int Month, int Year)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Month", "@Year" };
            object[] myValues = new object[] { Month, Year };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_TIMEKEEPER_TABLELIST_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Finish(Guid TimeKeeperTableListID)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID" };
            object[] myValues = new object[] { TimeKeeperTableListID };
            SqlHelper helper = new SqlHelper {
                CommandType = CommandType.Text
            };
            return helper.ExecuteNonQuery("Update HRM_TIMEKEEPER_TABLELIST set IsLock='1',IsFinish='1' Where TimeKeeperTableListID=@TimeKeeperTableListID", myParams, myValues);
        }

        public string Get(int Month, int Year)
        {
            string str = "";
            string[] myParams = new string[] { "@Month", "@Year" };
            object[] myValues = new object[] { Month, Year };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_TIMEKEEPER_TABLELIST_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_TimeKeeperTableListID = reader.GetGuid(reader.GetOrdinal("TimeKeeperTableListID"));
                    this.m_TimeKeeperTableListName = Convert.ToString(reader["TimeKeeperTableListName"]);
                    this.m_Month = Convert.ToInt32(reader["Month"]);
                    this.m_Year = Convert.ToInt32(reader["Year"]);
                    this.m_IsLock = Convert.ToBoolean(reader["IsLock"]);
                    this.m_IsFinish = Convert.ToBoolean(reader["IsFinish"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, int Month, int Year)
        {
            string str = "";
            string[] myParams = new string[] { "@Month", "@Year" };
            object[] myValues = new object[] { Month, Year };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "HRM_TIMEKEEPER_TABLELIST_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_TimeKeeperTableListID = reader.GetGuid(reader.GetOrdinal("TimeKeeperTableListID"));
                    this.m_TimeKeeperTableListName = Convert.ToString(reader["TimeKeeperTableListName"]);
                    this.m_Month = Convert.ToInt32(reader["Month"]);
                    this.m_Year = Convert.ToInt32(reader["Year"]);
                    this.m_IsLock = Convert.ToBoolean(reader["IsLock"]);
                    this.m_IsFinish = Convert.ToBoolean(reader["IsFinish"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, int Month, int Year)
        {
            string str = "";
            string[] myParams = new string[] { "@Month", "@Year" };
            object[] myValues = new object[] { Month, Year };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "HRM_TIMEKEEPER_TABLELIST_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_TimeKeeperTableListID = reader.GetGuid(reader.GetOrdinal("TimeKeeperTableListID"));
                    this.m_TimeKeeperTableListName = Convert.ToString(reader["TimeKeeperTableListName"]);
                    this.m_Month = Convert.ToInt32(reader["Month"]);
                    this.m_Year = Convert.ToInt32(reader["Year"]);
                    this.m_IsLock = Convert.ToBoolean(reader["IsLock"]);
                    this.m_IsFinish = Convert.ToBoolean(reader["IsFinish"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string GetByID(Guid TimeKeeperTableListID)
        {
            string str = "";
            string[] myParams = new string[] { "@TimeKeeperTableListID" };
            object[] myValues = new object[] { TimeKeeperTableListID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_TIMEKEEPER_TABLELIST_GetByID", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_TimeKeeperTableListID = reader.GetGuid(reader.GetOrdinal("TimeKeeperTableListID"));
                    this.m_TimeKeeperTableListName = Convert.ToString(reader["TimeKeeperTableListName"]);
                    this.m_Month = Convert.ToInt32(reader["Month"]);
                    this.m_Year = Convert.ToInt32(reader["Year"]);
                    this.m_IsLock = Convert.ToBoolean(reader["IsLock"]);
                    this.m_IsFinish = Convert.ToBoolean(reader["IsFinish"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_TIMEKEEPER_TABLELIST_GetList");
        }

        public DataTable GetListByYear(int Year)
        {
            string[] myParams = new string[] { "@Year" };
            object[] myValues = new object[] { Year };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_TIMEKEEPER_TABLELIST_GetListByYear", myParams, myValues);
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID", "@TimeKeeperTableListName", "@Month", "@Year", "@IsLock", "@IsFinish" };
            object[] myValues = new object[] { this.m_TimeKeeperTableListID, this.m_TimeKeeperTableListName, this.m_Month, this.m_Year, this.m_IsLock, this.m_IsFinish };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_TABLELIST_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID", "@TimeKeeperTableListName", "@Month", "@Year", "@IsLock", "@IsFinish" };
            object[] myValues = new object[] { this.m_TimeKeeperTableListID, this.m_TimeKeeperTableListName, this.m_Month, this.m_Year, this.m_IsLock, this.m_IsFinish };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_TIMEKEEPER_TABLELIST_Insert", myParams, myValues);
        }

        public string Insert(Guid TimeKeeperTableListID, string TimeKeeperTableListName, int Month, int Year, bool IsLock, bool IsFinish)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID", "@TimeKeeperTableListName", "@Month", "@Year", "@IsLock", "@IsFinish" };
            object[] myValues = new object[] { TimeKeeperTableListID, TimeKeeperTableListName, Month, Year, IsLock, IsFinish };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_TIMEKEEPER_TABLELIST_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, Guid TimeKeeperTableListID, string TimeKeeperTableListName, int Month, int Year, bool IsLock, bool IsFinish)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID", "@TimeKeeperTableListName", "@Month", "@Year", "@IsLock", "@IsFinish" };
            object[] myValues = new object[] { TimeKeeperTableListID, TimeKeeperTableListName, Month, Year, IsLock, IsFinish };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_TIMEKEEPER_TABLELIST_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, Guid TimeKeeperTableListID, string TimeKeeperTableListName, int Month, int Year, bool IsLock, bool IsFinish)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID", "@TimeKeeperTableListName", "@Month", "@Year", "@IsLock", "@IsFinish" };
            object[] myValues = new object[] { TimeKeeperTableListID, TimeKeeperTableListName, Month, Year, IsLock, IsFinish };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_TIMEKEEPER_TABLELIST_Insert", myParams, myValues);
        }

        public string Lock(Guid TimeKeeperTableListID)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID" };
            object[] myValues = new object[] { TimeKeeperTableListID };
            SqlHelper helper = new SqlHelper {
                CommandType = CommandType.Text
            };
            return helper.ExecuteNonQuery("Update HRM_TIMEKEEPER_TABLELIST set IsLock='1' Where TimeKeeperTableListID=@TimeKeeperTableListID", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("HRM_TIMEKEEPER_TABLELIST", "TimeKeeperTableListID", "CV");
        }

        public string Open(Guid TimeKeeperTableListID)
        {
            string[] myParams = new string[] { "@TimeKeeperTableListID" };
            object[] myValues = new object[] { TimeKeeperTableListID };
            SqlHelper helper = new SqlHelper {
                CommandType = CommandType.Text
            };
            return helper.ExecuteNonQuery("Update HRM_TIMEKEEPER_TABLELIST set IsLock='0'Where TimeKeeperTableListID=@TimeKeeperTableListID", myParams, myValues);
        }

        [Category("Column"), DisplayName("IsFinish")]
        public bool IsFinish
        {
            get
            {
                return this.m_IsFinish;
            }
            set
            {
                this.m_IsFinish = value;
            }
        }

        [Category("Column"), DisplayName("IsLock")]
        public bool IsLock
        {
            get
            {
                return this.m_IsLock;
            }
            set
            {
                this.m_IsLock = value;
            }
        }

        [DisplayName("Month"), Category("Column")]
        public int Month
        {
            get
            {
                return this.m_Month;
            }
            set
            {
                this.m_Month = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class HRM_TIMEKEEPER_TABLELIST";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }

        [DisplayName("TimeKeeperTableListID"), Category("Primary Key")]
        public Guid TimeKeeperTableListID
        {
            get
            {
                return this.m_TimeKeeperTableListID;
            }
            set
            {
                this.m_TimeKeeperTableListID = value;
            }
        }

        [Category("Column"), DisplayName("TimeKeeperTableListName")]
        public string TimeKeeperTableListName
        {
            get
            {
                return this.m_TimeKeeperTableListName;
            }
            set
            {
                this.m_TimeKeeperTableListName = value;
            }
        }

        [DisplayName("Year"), Category("Column")]
        public int Year
        {
            get
            {
                return this.m_Year;
            }
            set
            {
                this.m_Year = value;
            }
        }
    }
}

